<template>
  <div>
    <el-dialog title="生产订单选择"
      v-if="showFlag"
      :visible.sync="showFlag"
      :modal= false
      width="60%"
      center
    >
      <el-row>
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
          <el-form-item label="订单编码" prop="orderCode">
            <el-input
              v-model="queryParams.orderCode"
              placeholder="请输入物料编码"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="订单名称" prop="orderName">
            <el-input
              v-model="queryParams.orderName"
              placeholder="请输入物料名称"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </el-row>

      <el-table v-loading="loading" :data="itemList"  @current-change="handleCurrent" @row-dblclick="handleRowDbClick">
        <el-table-column width="50" align="center" >
          <template v-slot="scope">
            <el-radio v-model="selectedItemId" :label="scope.row.id" @change="handleRowChange(scope.row)">{{""}}</el-radio>
          </template>
        </el-table-column>
        <el-table-column label="订单编码" align="center" key="orderCode" prop="orderCode" >
        </el-table-column>
        <el-table-column label="订单名称" align="center" key="orderName" prop="orderName" :show-overflow-tooltip="true" />
        <el-table-column label="订单类型" align="center" key="orderSourceDesc" prop="orderSourceDesc" :show-overflow-tooltip="true" />
        <el-table-column label="产品编码" align="center" key="planCode" prop="planCode" :show-overflow-tooltip="true" />
        <el-table-column label="产品名称" align="center" key="planName" prop="planName" width="120" />
        <el-table-column label="单位" align="center" key="unitOfMeasure" prop="unitOfMeasure" :show-overflow-tooltip="true" />
        <el-table-column label="创建时间" align="center" prop="createTime" width="160">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmSelect">确 定</el-button>
        <el-button @click="showFlag=false">取 消</el-button>
    </div>
    </el-dialog>
  </div>
</template>

<script>
import { orderList, addOrder, updateOrder, deleteOrder } from "@/api/mes/pro/order";
export default {
  name: 'productionOrderSelect',
  data() {
    return {
      loading: false,
      showFlag:false,
      // 选中数组
      selectedItemId: undefined,
      selectedRows: undefined,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderCode: undefined,
        orderName: undefined,
      },
      itemList: [],
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList(){
      this.loading = true;
      orderList(this.queryParams).then(response => {
        this.itemList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleCurrent(row){
        if(row){
            this.selectedRows = row;
        }
    },
    handleRowDbClick(row){
      if(row){
        this.selectedRows = row;
        this.$emit('onSelected',this.selectedRows);
        this.showFlag = false;
      }
    },
    // 单选选中数据
    handleRowChange(row) {
      if(row){
        this.selectedRows = row;
      }
    },
    //确定选中
    confirmSelect(){
      if(this.selectedItemId ==null || this.selectedItemId==0){
            this.$notify({
                title:'提示',
                type:'warning',
                message: '请至少选择一条数据!'
            });
            return;
        }
        this.$emit('onSelected',this.selectedRows);
        this.showFlag = false;
    }
  }
}
</script>

<style lang="scss" scoped>

</style>